package org.example.ttms.controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.StackPane;
import org.example.ttms.Main;
import org.example.ttms.customize.Pop_ups;
import org.example.ttms.entityClass.Manager;
import org.example.ttms.entityClass.train.Station;

public class ManagerController {
    @FXML
    private TabPane tabPane;

    //站台管理
    @FXML
    private Button searchStationButton;

    @FXML
    private Button addStationButton;

    @FXML
    private Button allStationButton;

    @FXML
    private StackPane stackPane;

    @FXML
    private TextField textField;

    //路线管理
    @FXML
    private Button addRouteButton;

    @FXML
    private Button allRouteButton;

    @FXML
    private Button searchRouteButton;

    @FXML
    private StackPane stackPane2;

    //车次管理
    @FXML
    private Button addTripsButton;

    @FXML
    private Button allTripsButton;

    @FXML
    private Button searchTripsButton;

    @FXML
    private StackPane stackPane3;

    @FXML
    private StackPane stackPane5;

    public static int type;
    public static String name;
    public static Manager manager;

    public Button getSearchStationButton() {
        return searchStationButton;
    }

    public void setSearchStationButton(Button searchStationButton) {
        this.searchStationButton = searchStationButton;
    }

    public Button getAddStationButton() {
        return addStationButton;
    }

    public void setAddStationButton(Button addStationButton) {
        this.addStationButton = addStationButton;
    }

    public Button getAllStationButton() {
        return allStationButton;
    }

    public void setAllStationButton(Button allStationButton) {
        this.allStationButton = allStationButton;
    }

    public StackPane getStackPane() {
        return stackPane;
    }

    public void setStackPane(StackPane stackPane) {
        this.stackPane = stackPane;
    }

    public TextField getTextField() {
        return textField;
    }

    public void setTextField(TextField textField) {
        this.textField = textField;
    }

    public Button getAddRouteButton() {
        return addRouteButton;
    }

    public void setAddRouteButton(Button addRouteButton) {
        this.addRouteButton = addRouteButton;
    }

    public Button getAllRouteButton() {
        return allRouteButton;
    }

    public void setAllRouteButton(Button allRouteButton) {
        this.allRouteButton = allRouteButton;
    }

    public Button getSearchRouteButton() {
        return searchRouteButton;
    }

    public void setSearchRouteButton(Button searchRouteButton) {
        this.searchRouteButton = searchRouteButton;
    }

    public StackPane getStackPane2() {
        return stackPane2;
    }

    public void setStackPane2(StackPane stackPane2) {
        this.stackPane2 = stackPane2;
    }

    public TabPane getTabPane() {
        return tabPane;
    }

    public void setTabPane(TabPane tabPane) {
        this.tabPane = tabPane;
    }

    public Button getAddTripsButton() {
        return addTripsButton;
    }

    public void setAddTripsButton(Button addTripsButton) {
        this.addTripsButton = addTripsButton;
    }

    public Button getAllTripsButton() {
        return allTripsButton;
    }

    public void setAllTripsButton(Button allTripsButton) {
        this.allTripsButton = allTripsButton;
    }

    public Button getSearchTripsButton() {
        return searchTripsButton;
    }

    public void setSearchTripsButton(Button searchTripsButton) {
        this.searchTripsButton = searchTripsButton;
    }

    public StackPane getStackPane3() {
        return stackPane3;
    }

    public void setStackPane3(StackPane stackPane3) {
        this.stackPane3 = stackPane3;
    }

    public void initialize(){
        tabPane.getSelectionModel().selectedItemProperty().addListener((obs, oldTab, newTab) -> {
            if(oldTab.getText().equals("站点管理")){
                stackPane.getChildren().clear();
            }
            else if(oldTab.getText().equals("路线管理")){
                stackPane2.getChildren().clear();
            }
            else if(oldTab.getText().equals("车次管理")){
                stackPane3.getChildren().clear();
            }
            else if(oldTab.getText().equals("个人中心")){
                stackPane5.getChildren().clear();
            }
            if(newTab.getText().equals("个人中心")){
                Main.jumpPage2(stackPane5, "managerMessage.fxml");
            }
        });
    }

    //站点管理
    @FXML
    void chickAddStation(ActionEvent event) {
        type = 0;
        textField.setText("");
        Main.jumpPage2(stackPane, "addStation.fxml");
    }

    @FXML
    void chickAllStation(ActionEvent event) {
        type = 0;
        textField.setText("");
        Main.jumpPage2(stackPane, "stationTableView.fxml");
    }

    @FXML
    void chickSearchStation(ActionEvent event) {
        if(!searchStationJudgement(textField.getText()))
            return ;
        type = 1;
        name = textField.getText();
        Main.jumpPage2(stackPane, "stationTableView.fxml");
    }

    //站台搜索评判
    public boolean searchStationJudgement(String name){
        Station station = new Station();
        if(station.searchStation(name) == null){
            Pop_ups popUps = new Pop_ups();
            popUps.pop_ups3("站台不存在");
            return false;
        }
        return true;
    }

    //路线管理
    @FXML
    void chickAddRoute(ActionEvent event) {
        Main.jumpPage2(stackPane2, "addRoute.fxml");
    }

    @FXML
    void chickAllRoute(ActionEvent event) {
        Main.jumpPage2(stackPane2, "routeTableView.fxml");
    }

    @FXML
    void chickSearchRoute(ActionEvent event) {
        Main.jumpPage2(stackPane2, "searchRoute.fxml");
    }

    //车次管理
    @FXML
    void chickAddTrips(ActionEvent event) {
        Main.jumpPage2(stackPane3, "addTrips.fxml");
    }

    @FXML
    void chickAllTrips(ActionEvent event) {
        Main.jumpPage2(stackPane3, "tripsTableView.fxml");
    }

    @FXML
    void chickSearchTrips(ActionEvent event) {
        Main.jumpPage2(stackPane3, "searchTrips.fxml");
    }
}
